//
//  MeSecurityViewController.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/9.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "MeSecurityViewController.h"
#import "DWEditUserInfoCell.h"
#import "MeBindEmailViewController.h"

@interface MeSecurityViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView    *tableView;
@property (nonatomic,strong)NSArray        *cellArray;

@end

@implementation MeSecurityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"安全认证";
    self.cellArray = @[@"手机号码",@"邮箱"];
    [self.view addSubview:self.tableView];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setBlackStatus:YES];
    [self.tableView reloadData];
}
#pragma mark - init
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, distanceHeight , KScreenWidth, KScreenHeight-distanceHeight) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor clearColor];
        _tableView.scrollEnabled = YES;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
    }
    return _tableView;
}
#pragma mark - UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.cellArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DWEditUserInfoCell *cell = [DWEditUserInfoCell cellWithTableViewImageWidth:tableView];
    cell.lbtitle.text =self.cellArray[indexPath.row];
    if (indexPath.row == 0) {
        if ([UserCenter shareCenter].user.phone.length > 0) {
            NSMutableString *string1 = [UserCenter shareCenter].user.phone.mutableCopy;
            [string1 replaceCharactersInRange:NSMakeRange(3, 6) withString:@"****"];
            cell.lbcontent.text = string1;
        }
    }else{
        NSString *strEmail = [UserCenter shareCenter].user.email;
        if (strEmail.length>0) {
            cell.lbcontent.text = strEmail;
        }else{
            cell.lbcontent.text = @"未绑定";
        }
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1) {
        [self.navigationController pushViewController:[MeBindEmailViewController new] animated:YES];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
